﻿using Elasticsearch.Net;
using Nest;
using PMS.Search.Domain.Entities;
using PMS.Search.Elasticsearch;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace ElasticSearchTest
{
    public class EsClient
    {
        ////ES搜索配置
        //"SearchConfig": {
        //  "ServerUrl": "http://10.1.0.2:9200/;http://10.1.0.6:9200/;http://10.1.0.11:9200/",
        //  "DefultIndexName": "",
        //  "NumberOfReplicas": 2,
        //  "NumberOfShards": 3
        //},
        //private static string prefix = "uat_";
        private static string prefix = EsIndexConfig.prefix;
        private static string suffix = EsIndexConfig.suffix;

        private string _defaultIndex = "defaultindex";
        //index名称使用别名
        private readonly string _schoolIndexName = "school";
        private readonly string _schoolRankIndexName = "schoolrank";
        private readonly string _commentIndexName = "comment";
        private readonly string _questionIndexName = "question";
        private readonly string _answerIndexName = "answer";
        private readonly string _liveIndexName = "live";
        private readonly string _articleIndexName = "article";
        private readonly string _singSchoolIndexName = "sign";
        private readonly string _BTschoolSearchIndexName = "schsearch";
        private readonly string _topicIndexName = prefix + "topic" + suffix;
        private readonly string _topicIndexName_real = prefix + "topicindex" + suffix;
        private readonly string _circleIndexName = prefix + "circle" + suffix;
        private readonly string _circleIndexName_real = prefix + "circleindex" + suffix;
        //private readonly string _topicIndexNameTest = "topic_test_2";
        //private readonly string _topicIndexNameTest = "topic_test";

        public ElasticClient GetClient()
        {
            var nodes = new Uri[] {
               //new Uri("http://elastic:sxb9394@10.1.0.2:9200/"),
               //new Uri("http://elastic:sxb9394@10.1.0.6:9200/"),
               //new Uri("http://elastic:sxb9394@10.1.0.11:9200/")

               new Uri("http://elastic:sxb123@10.1.0.7:9200/")
            };
            var poll = new StaticConnectionPool(nodes);
            var setting = new ConnectionSettings(poll);
            setting.DefaultIndex(_defaultIndex);

            var client = new ElasticClient(setting);
            return client;
        }
    }
}
